package program;
import java_cup.runtime.Symbol;


%%

%{
	// ukljucivanje informacije o poziciji tokena
	private Symbol new_symbol(int type) {
		return new Symbol(type, yyline+1, yycolumn);
	}
	// ukljucivanje informacije o poziciji tokena
	private Symbol new_symbol(int type, Object value) {
		return new Symbol(type, yyline+1, yycolumn, value);
	}
%}

// Sluzi za implementiranje java_cup.runtime.Scanner i ima samo metood next symbol
%cup

%public

%xstate COMMENT

%eofval{ 
	return new_symbol(sym.EOF);
%eofval}

%line
%column

%% 


// leksicke strukture

" " 	{}
"\b" 	{}
"\t" 	{}
"\r\n" 	{}
"\f" 	{}
"break" { return new_symbol(sym.BREAK, yytext()); }
"class" { return new_symbol(sym.CLASS, yytext()); }
"else"  { return new_symbol(sym.ELSE, yytext()); }
"final" { return new_symbol(sym.FINAL, yytext()); }
"if"	{ return new_symbol(sym.IF, yytext()); }
"new"   { return new_symbol(sym.NEW, yytext()); }
"print" { return new_symbol(sym.PRINT, yytext()); }
"read"  { return new_symbol(sym.READ, yytext()); }
"void"  { return new_symbol(sym.VOID, yytext()); }
"while" { return new_symbol(sym.WHILE, yytext()); }
"return" { return new_symbol(sym.RETURN, yytext()); }
"+"    { return new_symbol(sym.PLUS, yytext()); }
"-"    { return new_symbol(sym.MINUS, yytext()); }
"*"    { return new_symbol(sym.MUL, yytext()); }
"/"    { return new_symbol(sym.DIV,	yytext()); }
"%"    { return new_symbol(sym.PERCENT, yytext()); }
"=="   { return new_symbol(sym.EQUALEQUAL, yytext());  }
"!="   { return new_symbol(sym.DIFFERENT, yytext()); }
">"    { return new_symbol(sym.GREATER, yytext()); }
">="   { return new_symbol(sym.GREATEREQUAL, yytext()); }
"<"    { return new_symbol(sym.LESS, yytext()); }
"<="   { return new_symbol(sym.LESSEQUAL, yytext()); }
"&&"   { return new_symbol(sym.AND, yytext()); }
"||"   { return new_symbol(sym.OR, yytext());  }
"="    { return new_symbol(sym.EQUAL, yytext()); }
"++"   { return new_symbol(sym.PLUSPLUS, yytext()); }
"--"   { return new_symbol(sym.MINUSMINUS, yytext()); }
";"	   { return new_symbol(sym.SEMICOLON, yytext()); }
","    { return new_symbol(sym.COMMA, yytext()); }
"("    { return new_symbol(sym.LBRACE, yytext()); }
")"    { return new_symbol(sym.RBRACE, yytext()); }
"["    { return new_symbol(sym.LSQUARE, yytext());  }
"]"    { return new_symbol(sym.RSQUARE, yytext()); }
"{"    { return new_symbol(sym.LCURLY, yytext()); }
"}"    { return new_symbol(sym.RCURLY, yytext()); }
"."	   { return new_symbol(sym.DOT, yytext()); }

"//" 		{ yybegin(COMMENT); }
<COMMENT>. 	{ yybegin(COMMENT); }

<COMMENT>"\r\n" 				{ yybegin(YYINITIAL); }
[0-9]+ 							{ return new_symbol(sym.NUMBER, new Integer (yytext()));}
([a-z]|[A-Z])[a-z|A-Z|0-9|_]* 	{ return new_symbol (sym.IDENT, yytext());}

"'"[\040-\176]"'" 				{ return new_symbol (sym.CHARCONST, new Character (yytext().charAt(1)));}

. 								{ return new_symbol(sym.INVALID, yytext()); }

